using System;
using JK.EventRouter.Eventing;
using JK.EventRouter.WorkItems;

namespace JK.EventRouter
{
    public interface IEventRouter : IDisposable
    {
        /// <summary>Subscribe an implementation of <see cref="IAction{T}"/> where T is an implementation of IWorkItem.  
        /// Depending on the implementation of IAction, work may be processed on a background thread <see cref="BackgroundThreadAction{T}"/> 
        /// OR marshalled to the gui thread <see cref="GuiThreadAction{T}"/> 
        /// </summary>
        void Subscribe<T>(object subscriber, IAction<T> action) where T : IWorkItem;

        /// <summary></summary>
        void Unsubscribe<T>(object subscriber) where T : IWorkItem;

        /// <summary>Publish a IWorkItem instance for consumption by one or more subscribers</summary>
        void Publish<T>(T item) where T : IWorkItem;

        /// <summary>Execute an action, invoking the callback when the action is completed</summary>
        void Execute(IAction action, IAction callback);
        
        /// <summary>Execute a simple action on the eventRouter</summary>
        void Execute(IAction action);

        IEventRouter SetBeforeWorkDelegate(Act beforeWork);
        IEventRouter SetAfterWorkDelegate(Act afterWork);
        IEventRouter SetOnExceptionDelegate(ExceptionEventHandler onException);
    }
}